package homework.service;

import com.sun.org.apache.xpath.internal.operations.Bool;
import homework.model.Penguin;

import java.util.ArrayList;
import java.util.List;

/**
 * List
 */
public class PenguinManage1 {
    static List list=new ArrayList();

    static {
        Penguin p1 = new Penguin("欧欧", "Q仔");
        Penguin p2 = new Penguin("亚亚", "Q妹");
        Penguin p3 = new Penguin("菲菲", "Q妹");
        Penguin p4 = new Penguin("美美", "Q妹");
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
    }

    public static void main(String[] args) {

        show1();
        delete();
        findPenguin();
    }

    private static void findPenguin() {
        Boolean flag=false;
        for (Object obj:list){
            Penguin p= (Penguin) obj;
            if (p.getName().equals("美美")){
                System.out.println("集合中在存在美美的信息");
                flag=true;
                break;
            }
        }
        if (!flag){
            System.out.println("集合中没有美美的信息");
        }
    }

    private static void delete() {
        list.remove(3);
        list.remove(2);
        int size = list.size();
        System.out.println("删除之后还有"+size+"只企鹅。");
        show2();
        System.out.println();

    }

    private static void show1() {
        int size = list.size();
        System.out.println("共计有"+size+"只企鹅。");
        show2();
        System.out.println();
    }

    private static void show2() {
        System.out.println("分别是：");
        for (Object obj:list){
            Penguin p= (Penguin) obj;
            System.out.println(p.getName()+" "+p.getGender());
        }
    }


}
